﻿@model NReco.PivotData.PivotData
@using NReco.PivotData

@{
	var json = new System.Web.Script.Serialization.JavaScriptSerializer();
	var categories = Model.GetDimensionKeys(new[]{"category"})[0];
	var rounds = Model.GetDimensionKeys(new[] { "round" })[0];	
}

<div id="chart1" style="width: 100%; height:400px;"></div>
<div id="chart2" style="width: 100%; height:400px;"></div>

<script type="text/javascript">
	google.load("visualization", "1", { packages: ["corechart"] });
	google.setOnLoadCallback(drawVisualization);

	function drawVisualization() {

		var data1 = google.visualization.arrayToDataTable([
			['Category','Raised Funds (count)'],
			@foreach (var category in categories) {
				<text>
				['@( String.IsNullOrEmpty(category.ToString()) ? "(unknown)" : category.ToString() )', @(((CompositeAggregator)Model[Key.Empty,category,Key.Empty,Key.Empty,Key.Empty]).Aggregators[0].Value) ],
				</text>
			}
		]);

		var options = {
			title: 'Raised Count by Category'
		};
		var chart1 = new google.visualization.PieChart(document.getElementById('chart1'));
		chart1.draw(data1, options);


		var data2 = google.visualization.arrayToDataTable([
			['Round','Raised Amount'],
			@foreach (var round in rounds) {
			<text>
			['@( String.IsNullOrEmpty(round.ToString()) ? "(unknown)" : round.ToString())', @(((CompositeAggregator)Model[Key.Empty,Key.Empty,Key.Empty,Key.Empty,round]).Aggregators[1].Value) ],
				</text>
			}
		]);

		var options = {
			title: 'Raised Amount by Round'
		};
		var chart2 = new google.visualization.ColumnChart(document.getElementById("chart2"));
		chart2.draw(data2, options);

	};
</script>